/*
 * DataModel.java
 *
 * Created on 25 de Julho de 2011, 10:55
 *
 */

package intopo.demonstrator.partnerselection.gui;

import intopo.demonstrator.partnerselection.Parameters;
import intopo.demonstrator.partnerselection.State;
import intopo.demonstrator.partnerselection.MarkovChain;

import java.util.Vector;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 25 de Julho de 2011
 */
public class DataModel
{
	/**
	 * The parameters that the user has selected.
	 */
	static final Parameters parameters;
	/**
	 * The current state of the partner classification model.
	 */
	static State currentState;
	/**
	 * Statistics of the current run of the partner classification model.
	 */
	static MarkovChain markovChain;
	/**
	 * State history of the partner classification model.
	 */
	static final Vector<State> history;
	static
	{
		parameters = new Parameters ();
		history = new Vector<State> (1000, 1000);
		parametersChanged ();
	}
	/**
	 * Initialises data if the parameters have changed or a new run is to be performed.
	 */
	static void parametersChanged ()
	{
		DataModel.markovChain = new MarkovChain (DataModel.parameters);
		DataModel.currentState = DataModel.markovChain.getState ();
		DataModel.history.clear ();
		DataModel.history.add (DataModel.currentState);
	}
	/**
	 * Performs a transition of the partner classification model.
	 */
	static boolean newTransition ()
	{
		State s = DataModel.markovChain.transit ();
		if (s != null) {
			DataModel.currentState = s;
			DataModel.history.add (DataModel.currentState);
			return true;
		}
		else {
			return false;
		}
	}
	static boolean newTransition (State.TransitionTo t)
	{
		State s = DataModel.markovChain.transit (t);
		if (s != null) {
			DataModel.currentState = s;
			DataModel.history.add (DataModel.currentState);
			return true;
		}
		else {
			return false;
		}
	}
	/**
	 * Indexed getter for property history.
	 * @param index Index of the property.
	 * @return Value of the property at <CODE>index</CODE>.
	 */
	static final State getHistory (int index)
	{
		return history.get (index);
	}
	/**
	 * This class is non instanciable.
	 */
	private DataModel ()
{
	}
	
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
